home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group92c.txt
/
000075_icon-group-sender _Fri Nov 6 04:40:10 1992.msg
< prev
next >
Wrap
Internet Message Format
|
1993-01-04
|
3KB
Received: by cheltenham.cs.arizona.edu; Thu, 12 Nov 1992 05:29:17 MST
Date: 6 Nov 92 04:40:10 GMT
From: srt@arizona.edu (Scott R. Trappe)
Subject: Rationale for sortf() second argument?
Message-Id: <25952@optima.cs.arizona.edu>
Sender: icon-group-request@cs.arizona.edu
To: icon-group@cs.arizona.edu
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
The sortf() function in Icon V8.7 is defined as:
sortf(X,i) Produces a sorted list of the elements of X. The
results are similar to those of sort(X,i),
except that among lists and among records,
structure values are ordered by comparing their
ith fields.
Can someone explain to me why the second argument to the sortf() function is
an integer index of the field in the record to sort on, instead of a string
containing the field name? As defined, this function seems to be very
dangerous, since adding, deleting, or re-ordering fields in a record could
change which field is used as the key. The programmer must manually inspect
each use of sortf() and verify that either it is not being used on data
structures containing the affected record type, or that the field index is
unaffected by the change.
It would seem that specifying the field name as a string is far safer; it makes
it obvious which field is used as the key, makes the program insensitive to
adding or re-ordering fields in the record, and should the field be deleted,
could result in a run-time error. It would seem to also improve program
readability, since in the typical case the field name would be a literal string
in the sortf() function. As it stands now, one has to go find the record
declaration and count the fields to find out which field is the key.
This is even more problematical if one is using an Icon pre-processor such as
Idol that adds extra fields to the BEGINNING of the record: without knowledge
of the transformations that the preprocessor makes, it is impossible to use the
sortf() function. Worse, changes to the pre-processor could silently break
"correct" code.
There seems to me to be precedent in Icon for supplying language identifiers
in strings; witness the proc() and args() functions. Indeed, in the very same
report where the sortf() function is described, there is a description of a
new feature whereby field selection can be done with a string operand, for
example:
record.["field1"]
can be used to mean:
record.field1
Scott Trappe